// 导入fs http path三个模块
const fs=require('fs')
const http=require('http')
const path=require('path')
const server=http.createServer()

server.on('request',(req,res)=>{
if(req.url==='/api/news'){
fs.readFile(path.join(__dirname ,'./list(1).json'),'utf-8',(err,dataStr)=>{
  if(err) res.end('404')
  res.setHeader("Access-Control-Allow-Origin", "*")
  res.setHeader('Content-Type','text/json;charset=utf-8')
  res.end(dataStr)
})
}
})
server.listen(8080,()=>{
console.log('启动服务器');
})